<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class chuongtrinhhoc_db 
	{
		public function Them($MaChuongTrinh, $TenChuongTrinh, $SoTiet, $HocPhi, $MaTrangThai, $GhiChu, $PIN)
		{
			$sql = "INSERT INTO `tbl_chuongtrinhhoc`(`MaChuongTrinh`, `TenChuongTrinh`, `SoTiet`, `HocPhi`, `MaTrangThai`, `GhiChu`, `PIN`)
					VALUES ('$MaChuongTrinh', '$TenChuongTrinh', '$SoTiet', '$HocPhi', '$MaTrangThai', '$GhiChu', '$PIN')";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($MaChuongTrinh)
		{
			$sql = "DELETE FROM `tbl_chuongtrinhhoc` WHERE `MaChuongTrinh` = '$MaChuongTrinh'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($MaChuongTrinh, $TenChuongTrinh, $SoTiet, $HocPhi, $MaTrangThai, $GhiChu, $PIN)
		{
			$sql = "UPDATE `tbl_chuongtrinhhoc`
					SET `TenChuongTrinh` = '$TenChuongTrinh', `SoTiet` = '$SoTiet', `HocPhi` = '$HocPhi', `MaTrangThai` = '$MaTrangThai', `GhiChu` = '$GhiChu', `PIN` = '$PIN'
					WHERE `MaChuongTrinh` = '$MaChuongTrinh'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($MaChuongTrinh, $TenChuongTrinh, $SoTiet, $HocPhi, $MaTrangThai, $GhiChu, $PIN)
		{
			$sql = "SELECT * FROM `tbl_chuongtrinhhoc` WHERE 1  ";
			if($MaChuongTrinh != "")
				$sql .= " AND `MaChuongTrinh` = '$MaChuongTrinh' ";

			if($TenChuongTrinh != "")
				$sql .= " AND `TenChuongTrinh` = '$TenChuongTrinh' ";

			if($SoTiet != -1)
				$sql .= " AND `SoTiet` = '$SoTiet' ";

			if($HocPhi != -1)
				$sql .= " AND `HocPhi` = '$HocPhi' ";

			if($MaTrangThai != -1)
				$sql .= " AND `MaTrangThai` = '$MaTrangThai' ";

			if($GhiChu != "")
				$sql .= " AND `GhiChu` = '$GhiChu' ";

			if($PIN != "")
				$sql .= " AND `PIN` = '$PIN' ";

			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

